package dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;

import to.Email;
import to.Cadastro;
import util.HibernateUtil;

public class CadastroDAO {

	public List<Email> buscaEmailInformado(String emailInformado) {

		List<Email> retornaEmail = new ArrayList<Email>();
		Session session = null;

		try {

			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Email.class, "e");
			criteria.add(Restrictions.eq("e.email", emailInformado));
			retornaEmail = (List<Email>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return retornaEmail;
	}

	public List<Cadastro> buscaCPFInformado(String cpfInformado) {

		List<Cadastro> retornaCpf = new ArrayList<Cadastro>();
		Session session = null;

		try {

			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Cadastro.class, "c");
			criteria.add(Restrictions.eq("c.cpf_cnpj", cpfInformado));
			retornaCpf = (List<Cadastro>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return retornaCpf;
	}

}
